import json
from analysis.parse import dbutils

class BraData():
    def __init__(self,d):
        self.__dict__ = d

'''
itemid          # itemi
cup             # 罩杯
area            # 地区
comment         # 评论
color,          # 胸罩颜色
clientshow      # 客户端显示
ismobile        # 是否是手机
'''

def parse(recordid):
    jsonfile = dbutils.get_jsondata_by_id(recordid)
    data = json.loads(jsonfile,object_hook=BraData)

    itemid = data.productCommentSummary.skuId
    comment_num = len(data.comments)
    for commentid in range(10):
        try:
            cup = data.comments[commentid].productSize
        except Exception as e:
            cup = ""
        try:
            area = data.comments[commentid].userProvince
        except Exception as e:
            area =""
        try:
            comment = data.comments[commentid].content
        except Exception as e:
            comment =""
        try:
            color = data.comments[commentid].productColor
        except Exception as e:
            color =""
        try:
            clientshow = data.comments[commentid].userClientShow
        except Exception as e:
            clientshow =""
        try:
            ismobile = data.comments[commentid].isMobile
        except Exception as e:
            ismobile = ""

        print(cup,area,comment,color,clientshow,ismobile)
        dbutils.save_data(itemid,cup,area,comment,color,clientshow,ismobile)




if __name__ == '__main__':
    record_num = dbutils.total_record
    for i in range(1,record_num+1,1):
        try:
            parse(i)
        except Exception as e:
            print("解析出错:{}".format(e[0]))
